package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 日报首页
 */
@Setter@Getter
public class News extends BaseDomain {

    public static final int STATE_REJECT = 0;//取消发布
    public static final int STATE_WAITING = 2;//待发布
    public static final int STATE_RELEASE = 3;//已发布

    private String title;//标题

    private String summary;//文章概要

    private String coverUrl;//封面

    private Date createTime;//创建时间

    private Integer state;//状态

    //一对一关系
    private NewsContent content;//关联日报的详情内容

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;//发布时间

    public String getStateDisplay() {
        if (state != null) {
            if (state == 0) {
                return "拒绝发布";
            }else if (state == 1) {
                return "正常";
            }else if (state == 2) {
                return "审核中";
            }else if (state == 3) {
                return "已发布";
            }
        }
        return "";
    }

    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("title",title);
        map.put("summary",summary);
        map.put("state",state);
        map.put("coverUrl",coverUrl);
        map.put("createTime",createTime);
        map.put("releaseTime",releaseTime);
        return JSONUtil.toJSONString(map);
    }

}